@isTest
private class test_CXGCallScript 
{
	static testMethod void myUnitTest1() 
	{
		Profile p = [select id from profile where name = 'System Administrator']; 
		User u = new User(alias = 'sysadmin', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname = 'Testing12', languagelocalekey='en_US',    localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username = 'testadmin123@testorg.com'); 
		insert u;
		User u1 = new User(alias = 'sysadmin', email='sysadmin@accenture.com',ManagerId = u.Id,emailencodingkey='UTF-8', lastname = 'Testing123', languagelocalekey='en_US',    localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username = 'testadmin1234@testorg.com'); 
		insert u1;
		
		Account acct = new Account();
		acct.Name = 'TestAccount';
		acct.CSS_CustomerID__c = '9171367619';
		insert acct;
		
		Campaign parentcamp = new Campaign();
		parentcamp.Name = 'Parent Campaign';
		parentcamp.StartDate = Date.today();
		parentcamp.EndDate = Date.today()+14;
		insert parentcamp;
		
		Campaign camp= new Campaign();
		camp.Name = 'Campaign Wave1';
		camp.ParentId = parentcamp.Id;
		camp.StartDate = Date.today();
		Camp.EndDate = Date.today() + 7;
		insert camp;
		
		CXG_Campaign_Accounts__c campaignmember = new CXG_Campaign_Accounts__c();
		campaignmember.Campaign__c = camp.Id;
		campaignmember.Customer__c = acct.Id;
		insert campaignmember;
		
		CXG_Campaign_Accounts__c campaignmember1 = new CXG_Campaign_Accounts__c();
		campaignmember1.Campaign__c = camp.Id;
		campaignmember1.Customer__c = acct.Id;
		insert campaignmember1;
		
		Id CxGEventRecordTypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Event', 'CXG_Record_Type');
		Event evnt = new Event();
		evnt.WhatId = acct.Id;
		evnt.StartDateTime = DateTime.now();
		DateTime dt = evnt.StartDateTime;
		evnt.EndDateTime = dt.addMinutes(30);
		evnt.Ownerid = u.Id;
		evnt.Subject = 'Test';
		evnt.RecordTypeId = CxGEventRecordTypeID;
		evnt.Owner_Manager__c = 'Testing12';
		insert evnt;
		
		List<Task> tsklist = new List<Task>();
		
		Task tsk = new Task(); 
		tsk.WhatId = campaignmember.Id;  
		tsk.Disposition__c = 'Customer Contacted';
		tsk.ActivityDate = Date.today(); 
		tsk.Attempt_Date__c = DateTime.now();
		tsk.Status='new'; 
		tsk.Priority='Normal';
		tsk.Subject = 'Test Subject'; 
		tsk.CXG_Account__c = true;
		tsk.Ownerid = u.Id;
		tsk.Owner_Manager__c = 'Testing12';
		
		Task tsk1 = new Task();
		tsk1.WhatId = campaignmember1.Id;  
		tsk1.Disposition__c = 'Add to Do Not Call List';
		tsk1.ActivityDate = Date.today(); 
		tsk1.Attempt_Date__c = DateTime.now();
		tsk1.Status = 'new'; 
		tsk1.Priority = 'Normal';
		tsk1.Subject = 'Test Subject'; 
		tsk1.CXG_Account__c = true; 
		tsk.Ownerid = u.Id;
		tsk.Owner_Manager__c = 'Testing12';
		
		tsklist.add(tsk);
		tsklist.add(tsk1);
		insert tsklist;
		
		campaignmember = new CXG_Campaign_Accounts__c(Id = tsk.WhatId);
		campaignmember.status__C = 'In Progress - Not Contacted'; 
		campaignmember.Disposition__c = tsk.Disposition__c; 
		campaignmember.Call_Resolution__c = tsk.Call_Resolutions__c;
		Integer i = 0;
		campaignmember.Number_of_times_Contacted__c = i+1; 
		campaignmember.Number_of_Call_Attempts_Made__c = i+1;		
		update campaignmember; 
		
		campaignmember1.status__C = 'Closed'; 
		campaignmember1.Disposition__c = tsk1.Disposition__c; 
		campaignmember1.Call_Resolution__c = tsk1.Call_Resolutions__c; 
		update campaignmember1;
		
		Script__c sct = new Script__c();
		sct.Name = 'Test Script';
		insert sct;
		
		Issue_Subissue__c issu = new Issue_Subissue__c();
		issu.Name = 'Test Issue';
		issu.Script__c = sct.Id;
		issu.Issue__c = 'Issue';
		issu.Subissue__c = 'Sub-Issue';
		insert issu;
		
		
		ApexPages.CurrentPage().getParameters().put('actid',acct.Id);
		ApexPages.CurrentPage().getParameters().put('campname',camp.Id);
		ApexPages.CurrentPage().getParameters().put('cmid',campaignmember.Id);
		
		ApexPages.StandardController sc = new ApexPages.StandardController(issu); 
		CallScriptController csc = new CallScriptController(sc);
		csc.createnoissuedisp();
		csc.onclickactionissue();
		csc.createdisp(); 
		csc.getItems();
		csc.test();
		csc.getValue();
		csc.getIssue();
		csc.getIssuedisp();
		csc.onclickaction();
		csc.getSubIssue();
		csc.getIssueidentfd();
		csc.getflag();
		csc.getflag1();
		csc.getissuechk();
		csc.getissueidentified();
		csc.getnextlnk();		
		csc.getaccount();
		csc.getMatrix();
		
		CXGCampaignMemberOperation.CampaignMemberStatusUpdate(tsklist);
		CXGCampaignMemberOperation.CampaignMemberCallsIncrement(tsklist);	
	}
	
	static testMethod void myUnitTest2() 
	{
		Profile p = [select id from profile where name = 'System Administrator']; 
		User u = new User(alias = 'sysadmin', email='sysadmin@accenture.com', 
			emailencodingkey='UTF-8', lastname = 'Testing', languagelocalekey='en_US', 
			localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username = 'testadmin@testorg.com');
		insert u;
		Id usr = Userinfo.getUserId();
		
		system.runAs(u)
		{
			Id CxGIOGcontactRecordtypID = RecordTypeHelper.GetRecordTypeIdByDevName('Contact', 'CSS_Contact'); 
			Integer hr;
			DateTime dt;
			dt = DateTime.now(); 
			hr = dt.hour(); 
			System.debug('Hour'+hr);
			
			Account acct = new Account();
			acct.Name = 'TestAccount';
			acct.Customer_ID__c = '9171367619';
			acct.BillingState = 'CT';
			acct.OwnerId = u.Id;
			insert acct;
			
			Contact cont = new Contact();
			cont.source_type__c = 'CSS';
			cont.MailingState = 'CT';
			cont.accountId = acct.Id;
			cont.RecordTypeId = CxGIOGcontactRecordtypID;
			cont.Phone = '123456';
			cont.LastName = 'TestLastName';
			insert cont;
			
			Contact cnt = [select Time_zone__c from Contact where Id = :cont.Id];
			System.debug('CNTTIME'+cnt.Time_zone__c);
			
			acct.CxG_Contact__c = cont.Id;
			acct.CxG_Contact_TimeZone__c = cnt.Time_zone__c; 
			update acct;			
			System.debug('ACCTTIMEZONE' + acct.CxG_Contact_TimeZone__c);
			
			Campaign parentcamp = new Campaign();
			parentcamp.Name = 'Parent Campaign';
			parentcamp.StartDate = Date.today();
			parentcamp.EndDate = Date.today() + 14;
			insert parentcamp;
			
			Campaign camp = new Campaign();
			camp.Name = 'Campaign Wave1';
			camp.ParentId = parentcamp.Id;
			camp.StartDate = Date.today();
			camp.Paused__c = false;
			Camp.EndDate = Date.today() + 7;
			insert camp;
			
			CXG_Campaign_Accounts__c campaignmember = new CXG_Campaign_Accounts__c();
			campaignmember.Campaign__c = camp.Id;
			campaignmember.Customer__c = acct.Id;
			campaignmember.Campaign_Paused__c = False;
			campaignmember.OwnerId = u.Id;
			campaignmember.Status__c = 'In Progress - Contacted'; 
			insert campaignmember;
			update campaignmember;			
			
			ApexPages.StandardController sc = new ApexPages.StandardController(campaignmember); 
			CXGSnapshotController cs = new CXGSnapshotController(sc);
			// These cases should find the 'In Progress - Contacted' member
			cs.CurrentHour = 1; // no match for timezones
			cs.NextCall();
			cs.CurrentHour = 7;
			cs.NextCall();
			cs.CurrentHour = 8;
			cs.NextCall();
			cs.CurrentHour = 9;
			cs.NextCall();
			cs.CurrentHour = 10;
			cs.NextCall();
			cs.CurrentHour = 17;
			cs.NextCall();
			cs.CurrentHour = 18;
			cs.NextCall();
			cs.CurrentHour = 19;
			cs.NextCall();
			
			// Create a member owned by the current user and set the member status = 'New'
			campaignmember = new CXG_Campaign_Accounts__c();
			campaignmember.Campaign__c = camp.Id;
			campaignmember.Customer__c = acct.Id;
			campaignmember.Campaign_Paused__c = False;
			campaignmember.OwnerId = UserInfo.getUserId();
			campaignmember.Status__c = 'New'; 
			insert campaignmember;	
			update campaignmember;	
			
			// This one should find the 'New' member
			cs.CurrentHour = 10;	
			cs.NextCall();
		}
	}
}